package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.QueryThingModelPublishedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author 聆听
 * @Date 2025-09-10
 */

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController extends BaseController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation("同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation("查询所有产品，下拉框产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        return success(deviceService.allProduct());
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation("设备注册")
    public ResponseResult addProduct(@RequestBody DeviceDto deviceDto) {
        deviceService.addProduct(deviceDto);
        return success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<DeviceVo>> findByPage(DevicePageQueryDto devicePageQueryDto) {
        PageResponse<DeviceVo> deviceVoPageResponse = deviceService.findByPage(devicePageQueryDto);
        return success(deviceVoPageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("根据id和key查询信息，编辑框回显")
    public ResponseResult<DeviceVo> findByIdKey(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest) {
        return success(deviceService.findByIdKey(queryDeviceDetailRequest));
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<QueryThingModelPublishedVo> QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        return success(deviceService.QueryThingModelPublished(request));
    }


    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态")
    public ResponseResult<QueryDeviceByStatusResponseBody.QueryDeviceByStatusResponseBodyDataSimpleDeviceInfo> QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return success(deviceService.QueryDevicePropertyStatus(request));
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation("修改设备")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return success();
    }

    @DeleteMapping("/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest) {
        deviceService.deleteDevice(deleteDeviceRequest);
        return success();
    }

}
